<template>
  <div v-loading="listLoading" class="app-container dashboard-editor-container" element-loading-text="数据加载中...">
    <div class="chart-wrapper" style="margin-bottom:32px;">
      <bar-chart v-if="flag" :chart-data="lineChartData" />
    </div>
    <el-table :data="list" border fit highlight-current-row>
      <el-table-column label="票种" align="center">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="人数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.author }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getShareList } from "@/api/ticketing";
import BarChart from "../../components/BarChart";

export default {
  components: { BarChart },
  data() {
    return {
      tableList: [],
      listLoading: false,
      listQuery: {
        activityId: localStorage.getItem("activityId")
      },
      lineChartData: {
        xName: [],
        barData: [],
        showName: [],
        total: 0
      },
      flag: false
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    async fetchData() {
      this.listLoading = true;
      const params = { ...this.listQuery };
      const { data } = await getShareList(params);
      if (data.success) {
        this.tableList = data.data.list;
        this.lineChartData.xName = [];
        this.lineChartData.barData = [];
        this.lineChartData.showName = ["渠道"];
        data.data.list.forEach(item => {
          this.lineChartData.xName.push(item.name);
          this.lineChartData.barData.push(item.number);
        });
        this.flag = true;
        this.listLoading = false;
        this.lineChartData.total = data.data.num;
      }
    }
  }
};
</script>
